package com.nuoniu.sibanyun.mapper.provider;

import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.entity.crm.Approval;
import org.apache.ibatis.jdbc.SQL;
import org.apache.poi.ss.formula.functions.T;

/**
 * @auther 小啊刚
 * @date 2020/7/10
 */
public class ApprovalMapperProvider {

    /**对应数据库表名**/
    private String TABLE_NAME = "approval";

    public String getList(Approval approval) {
        return new SQL() {
            {
                SELECT("*");
                FROM(TABLE_NAME);
                WHERE("status = 0");
                if(approval.getApprovalResult() != null) {
                    WHERE("approval_result = #{approvalResult}");
                }
                if(StringUtils.isNotBlank(approval.getProcessName())) {
                    WHERE("process_name like \"%\"#{processName}\"%\"");
                }
                if(approval.getApprovalSize() != null) {
                    WHERE("approval_size = #{approvalSize}");
                }
                if(approval.getApprovalType() != null) {
                    WHERE("approval_type = #{approvalType}");
                }
                if(approval.getSourceId() != null) {
                    WHERE("source_id = #{sourceId}");
                }
                if(approval.getProcessId() != null) {
                    WHERE("process_id = #{processId}");
                }
            }
        }.toString();
    }
}
